package A_review.review9_4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class Class40 {

    List<List<Integer>> result = new ArrayList<>();
    LinkedList<Integer> path = new LinkedList<>();
    int curSum = 0;
    boolean[]  record;
    void find(int[]  candidates, int target) {
        Arrays.sort(candidates);
        record=new boolean[candidates.length];
        backing(candidates,0,target,curSum);

    }


    void backing(int[] candidates,int start, int target, int curSum) {
        if (curSum > target) {
            return;
        }
        if ( curSum ==target) {
            result.add(new ArrayList<>(path));
            return;
        }
        for (int i = start; i <candidates.length; i++) {
            //TODO:2023/9/4 重点
            if (i>0&&candidates[i]== candidates[i-1]&&!record[i-1]){
                continue;
            }
            record[i]=true;
            curSum += candidates[i];
            path.add(candidates[i]);
            //TODO:2023/9/4  就这点和其他的不同呢
            backing(candidates,i+1,target,curSum);
            path.remove(path.size() - 1);
            curSum -= candidates[i];
            record[i]=false;
        }

    }

    public static void main(String[] args) {
        Class40 class40 = new Class40();
        int[]  candi={10,1,2,7,6,1,5};
        class40.find(candi,8);
        System.out.println(class40.result.toString());

    }







}
